{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56f7dbf8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09668d2a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cba1eedf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d33100bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# _*_ coding: utf-8 _*_\n",
    "\n",
    "\"\"\"\n",
    "python_visual_animation.py by xianhu\n",
    "\"\"\"\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.font_manager as fm\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "\n",
    "# 解决中文乱码问题\n",
    "myfont = fm.FontProperties(fname=\"/Library/Fonts/Songti.ttc\", size=14)\n",
    "matplotlib.rcParams[\"axes.unicode_minus\"] = False\n",
    "\n",
    "\n",
    "def simple_plot():\n",
    "    \"\"\"\n",
    "    simple plot\n",
    "    \"\"\"\n",
    "    # 生成画布\n",
    "    plt.figure(figsize=(8, 6), dpi=80)\n",
    "\n",
    "    # 打开交互模式\n",
    "    plt.ion()\n",
    "\n",
    "    # 循环\n",
    "    for index in range(100):\n",
    "        # 清除原有图像\n",
    "        plt.cla()\n",
    "\n",
    "        # 设定标题等\n",
    "        plt.title(\"动态曲线图\", fontproperties=myfont)\n",
    "        plt.grid(True)\n",
    "\n",
    "        # 生成测试数据\n",
    "        x = np.linspace(-np.pi + 0.1*index, np.pi+0.1*index, 256, endpoint=True)\n",
    "        y_cos, y_sin = np.cos(x), np.sin(x)\n",
    "\n",
    "        # 设置X轴\n",
    "        plt.xlabel(\"X轴\", fontproperties=myfont)\n",
    "        plt.xlim(-4 + 0.1*index, 4 + 0.1*index)\n",
    "        plt.xticks(np.linspace(-4 + 0.1*index, 4+0.1*index, 9, endpoint=True))\n",
    "\n",
    "        # 设置Y轴\n",
    "        plt.ylabel(\"Y轴\", fontproperties=myfont)\n",
    "        plt.ylim(-1.0, 1.0)\n",
    "        plt.yticks(np.linspace(-1, 1, 9, endpoint=True))\n",
    "\n",
    "        # 画两条曲线\n",
    "        plt.plot(x, y_cos, \"b--\", linewidth=2.0, label=\"cos示例\")\n",
    "        plt.plot(x, y_sin, \"g-\", linewidth=2.0, label=\"sin示例\")\n",
    "\n",
    "        # 设置图例位置,loc可以为[upper, lower, left, right, center]\n",
    "        plt.legend(loc=\"upper left\", prop=myfont, shadow=True)\n",
    "\n",
    "        # 暂停\n",
    "        plt.pause(0.1)\n",
    "\n",
    "    # 关闭交互模式\n",
    "    plt.ioff()\n",
    "\n",
    "    # 图形显示\n",
    "    plt.show()\n",
    "    return\n",
    "# simple_plot()\n",
    "\n",
    "\n",
    "def scatter_plot():\n",
    "    \"\"\"\n",
    "    scatter plot\n",
    "    \"\"\"\n",
    "    # 打开交互模式\n",
    "    plt.ion()\n",
    "\n",
    "    # 循环\n",
    "    for index in range(50):\n",
    "        # 清除原有图像\n",
    "        # plt.cla()\n",
    "\n",
    "        # 设定标题等\n",
    "        plt.title(\"动态散点图\", fontproperties=myfont)\n",
    "        plt.grid(True)\n",
    "\n",
    "        # 生成测试数据\n",
    "        point_count = 5\n",
    "        x_index = np.random.random(point_count)\n",
    "        y_index = np.random.random(point_count)\n",
    "\n",
    "        # 设置相关参数\n",
    "        color_list = np.random.random(point_count)\n",
    "        scale_list = np.random.random(point_count) * 100\n",
    "\n",
    "        # 画散点图\n",
    "        plt.scatter(x_index, y_index, s=scale_list, c=color_list, marker=\"o\")\n",
    "\n",
    "        # 暂停\n",
    "        plt.pause(0.2)\n",
    "\n",
    "    # 关闭交互模式\n",
    "    plt.ioff()\n",
    "\n",
    "    # 显示图形\n",
    "    plt.show()\n",
    "    return\n",
    "# scatter_plot()\n",
    "\n",
    "\n",
    "def three_dimension_scatter():\n",
    "    \"\"\"\n",
    "    3d scatter plot\n",
    "    \"\"\"\n",
    "    # 生成画布\n",
    "    fig = plt.figure()\n",
    "\n",
    "    # 打开交互模式\n",
    "    plt.ion()\n",
    "\n",
    "    # 循环\n",
    "    for index in range(50):\n",
    "        # 清除原有图像\n",
    "        fig.clf()\n",
    "\n",
    "        # 设定标题等\n",
    "        fig.suptitle(\"三维动态散点图\", fontproperties=myfont)\n",
    "\n",
    "        # 生成测试数据\n",
    "        point_count = 100\n",
    "        x = np.random.random(point_count)\n",
    "        y = np.random.random(point_count)\n",
    "        z = np.random.random(point_count)\n",
    "        color = np.random.random(point_count)\n",
    "        scale = np.random.random(point_count) * 100\n",
    "\n",
    "        # 生成画布\n",
    "        ax = fig.add_subplot(111, projection=\"3d\")\n",
    "\n",
    "        # 画三维散点图\n",
    "        ax.scatter(x, y, z, s=scale, c=color, marker=\".\")\n",
    "\n",
    "        # 设置坐标轴图标\n",
    "        ax.set_xlabel(\"X Label\")\n",
    "        ax.set_ylabel(\"Y Label\")\n",
    "        ax.set_zlabel(\"Z Label\")\n",
    "\n",
    "        # 设置坐标轴范围\n",
    "        ax.set_xlim(0, 1)\n",
    "        ax.set_ylim(0, 1)\n",
    "        ax.set_zlim(0, 1)\n",
    "\n",
    "        # 暂停\n",
    "        plt.pause(0.2)\n",
    "\n",
    "    # 关闭交互模式\n",
    "    plt.ioff()\n",
    "\n",
    "    # 图形显示\n",
    "    plt.show()\n",
    "    return\n",
    "# three_dimension_scatter()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00c28ada",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
